<?php
	
	include_once 'config.php';
	
	function connect()
	{
		if(mysql_connect(DB_DOMAIN,DB_USER,DB_PASS)) {}
			else
		die('Cannot connect to database');
	}
		
	function selectDatabase()
	{
		if(mysql_select_db(DB_NAME)) {}
			else
		die('Database does not exist');
	}
	
	function getAssoc($query) 
	{
		//get result
		$result = mysql_query($query);
		
		//fetch associative array
		$re = mysql_fetch_assoc($result);
		
		//free result
		mysql_free_result($result);
		
		//return result
		return $re;
	}
	
	function getFullAssoc($query) 
	{
		$out = array();
		
		//get result
		$result = mysql_query($query);

		while($row = mysql_fetch_assoc($result))
		{			
			$out[] = $row;
		}
		
		mysql_free_result($result);
		
		//return result
		return $out;
	}
	
	function getArray($query)
	{
		//get result
		$result = mysql_query($query);
		
		//fetch array
		$return = mysql_fetch_array($result);
		
		//free result
		mysql_free_result($result);
		
		//return result
		return $return;
	}

	function query($query)
	{
		return mysql_query($query);
	}
	
	function getRow($query)
	{
		$result = mysql_query($query);

		$out = mysql_fetch_row($result);

		mysql_free_result($result);
		
		return $out;
	}
	
	function countRows($query)
	{
		return mysql_num_rows(mysql_query($query));
	}
	
	function close() 
	{	
		if(mysql_close()){}
			else
		die('Cannot close database connection');
	}
?>